/*
 * @Author: liuzelin
 * @Date: 2023-09-09 20:01:06
 * @LastEditors: liuzelin
 * @LastEditTime: 2024-05-03 20:26:08
 * @Description: file content
 */
#pragma once

#include "panda-framework/panda/panda.hpp"
#include "session_param.hpp"

namespace Panda {
struct EndpointConfigure;

class PANDA_EXPORT EndpointInterface {
 public:
  class Listener {
   public:
    virtual void OnConnect(EndpointInterface *transport, const char *remote_ip,
                           uint16_t remote_port) = 0;
    virtual void OnDisConnect(EndpointInterface *transport) = 0;
    virtual void OnSessionConnect(EndpointInterface *transport,
                                  const SessionParam &param) = 0;
    virtual void OnSend(EndpointInterface* transport, uint8_t* data, size_t len) = 0;
    virtual void OnRecv(EndpointInterface *transport, uint8_t *data, size_t len,
                        uint32_t sid) = 0;
  };

 public:
  static EndpointInterface *CreateTransport(const EndpointConfigure &configure);
  virtual void Bind(const char *ip, uint16_t port) = 0;
  virtual void Connect(const char *ip, uint16_t port) = 0;
  virtual const SocketAddress &GetLocal() = 0;
  virtual const SocketAddress &GetRemote() = 0;
  virtual size_t Send(uint8_t *data, size_t len, const SessionParam &param) = 0;
  virtual void Close() = 0;
};

struct PANDA_EXPORT EndpointConfigure {
  // TODO Add Interface Send
  TransmissionChannel *channel = nullptr;
  EndpointInterface::Listener *listener = nullptr;
  uint16_t mtu = 1200;
  size_t ticket_ms = 50;
};
}  // namespace Panda